const UPDATE_MENU = (state, payload) => {
    state.flat_menu = [...payload];
}

const UPDATE_ICON = (state, payload) => {
    state.icon_menu = [...payload];
}

const INSERT_MENU=(state, payload)=>{
    state.flat_menu.push(payload);
}

const EDIT_MENU = (state, payload) => {
    state.flat_menu.forEach(element => {
        if (element.menu_id === payload[0]) {
            Object.assign(element, payload[1]);
        } else if (element.permission_id === payload[0]) {
            Object.assign(element, payload[1]);
        }
    });
}

const REMOVE_MENU = (state, payload) => {
    state.flat_menu.forEach((item,index) => {
        if(item.menu_id===payload[0]){
            state.flat_menu.splice(index,1);
        }
    });
}
const REMOVE_OPER = (state, payload) => {
    state.flat_menu.forEach((item,index) => {
        if(item.permission_id===payload){
            state.flat_menu.splice(index,1);
        }
    });
}
export default{
    UPDATE_MENU,
    UPDATE_ICON,
    INSERT_MENU,
    EDIT_MENU,
    REMOVE_MENU,
    REMOVE_OPER
}